home *** CD-ROM | disk | FTP | other *** search
/ QRZ! Ham Radio 8 / QRZ Ham Radio Callsign Database - Volume 8.iso / pc / files / ant_nec / necprmtl.z / necprmtl
Internet Message Format  |  1996-06-25  |  4KB

  1. From dbraun@iil.intel.com Mon Nov 15 05:58:39 1993
  2. From: dbraun@iil.intel.com (Doug Braun)
  3. Date: Mon, 15 Nov 1993 15:41:47 +0200
  4. To: nec-list@ee.ubc.ca
  5. Subject: Nifty utility to use with NEC
  6. Cc: dbraun@iil.intel.com
  7. Content-Length: 4024
  8. Status: RO
  9. X-Lines: 120
  10.  
  11.  
  12. One problem with NEC is that there are few ways to parameterize
  13. any of the input data points. If you have a complex geometry and
  14. you want to change it, you may have to re-calculate and edit a
  15. whole binch of numbers. The geometry rotation, translation, and
  16. reflection commands are useful, but not enough.
  17.  
  18. I wrote a little perl utility, "param". Param searchs for and
  19. evaluates algebraic expressions in the input file, and replaces
  20. them with their actual values. Below is the script, a sample
  21. input file, and the results of running it through the script.
  22. (Note that in this example, I could have used the GM command to
  23. do essentially the same thing, but I didn't have the
  24. documentation for the GM cpmmand at the time. By the way, I
  25. hacked nec.f a bit sdo it wouldn't choke on blank lines, and
  26. extra text after all the parameters on a line. This is not
  27. required for "param" to work, though.
  28.  
  29. Sample input file:
  30. ****************************************************************************************************8
  31.  
  32. # $diplen = 0.430     # Dipole length (approx 1/2 wave)
  33. # $sep = 0.30      # separation (diameter) of opposite dipoles   50
  34. # $angle = 30        # tilt angle    48
  35. # $wire = .005
  36.  
  37. # $theta = 2*3.1416/360*$angle
  38.  
  39. CE  299.7-mhz CP Lindenblad Antenna
  40. GW  1  7  {-$sep/2} {-$diplen/2*cos($theta)} {-$diplen/2*sin($theta)}   {-$sep/2}  {$diplen/2*cos($theta)}  {$diplen/2*sin($theta)}  {$wire}     Driven element  
  41. GW  2  7  {-$diplen/2*cos($theta)} {$sep/2} {-$diplen/2*sin($theta)}   {$diplen/2*cos($theta)} {$sep/2} {$diplen/2*sin($theta)}  {$wire}     Driven element 2
  42. GW  3  7  {$sep/2} {$diplen/2*cos($theta)} {-$diplen/2*sin($theta)}   {$sep/2}  {-$diplen/2*cos($theta)}  {$diplen/2*sin($theta)}  {$wire}     Driven element 3
  43. GW  4  7  {$diplen/2*cos($theta)} {-$sep/2} {-$diplen/2*sin($theta)}   {-$diplen/2*cos($theta)} {-$sep/2} {$diplen/2*sin($theta)}  {$wire}     Driven element 4
  44. GE  
  45. PT  -1
  46. EX  0  1  3  0  1.0  
  47. EX  0  2  3  0  1.0  
  48. EX  0  3  3  0  1.0  
  49. EX  0  4  3  0  1.0  
  50. RP  0 9  3 1110   90.0   0.0  -10.0  22.5
  51.  
  52. XQ  
  53. EN
  54.  
  55. ****************************************************************************************************8
  56. Output of "param", to be fed to NEC2:
  57. ****************************************************************************************************8
  58.  
  59. CE  299.7-mhz CP Lindenblad Antenna
  60. GW  1  7  -0.15 -0.186195 -0.1075   -0.15  0.186195  0.1075  0.005     Driven element  
  61. GW  2  7  -0.186195 0.15 -0.1075   0.186195 0.15 0.1075  0.005     Driven element 2
  62. GW  3  7  0.15 0.186195 -0.1075   0.15  -0.186195  0.1075  0.005     Driven element 3
  63. GW  4  7  0.186195 -0.15 -0.1075   -0.186195 -0.15 0.1075  0.005     Driven element 4
  64. GE  
  65. PT  -1
  66. EX  0  1  3  0  1.0  
  67. EX  0  2  3  0  1.0  
  68. EX  0  3  3  0  1.0  
  69. EX  0  4  3  0  1.0  
  70. RP  0 9  3 1110   90.0   0.0  -10.0  22.5
  71.  
  72. XQ  
  73. EN
  74.  
  75. ****************************************************************************************************8
  76. "Param" itself:
  77. ****************************************************************************************************8
  78.  
  79. #!/usr/local/bin/perl
  80.  
  81.     $# = "%.6g";   # Set default printing format
  82.  
  83.     $_definitions = "";
  84.  
  85.     while(<>)
  86.     {
  87.         if(m/^#/)       # look for declaration lines that start with #
  88.         {
  89.             s/^#\s*//;    # remove leading whitespace
  90.             s/\s*$//;    # remove trailing whitespace
  91.             eval($_);
  92.             #$_definitions = $_definitions . $_ . ";";   # append to master list
  93.         }
  94.         else
  95.         {
  96.             # Look for {} expressions
  97.  
  98.             while (m/{/)
  99.             {
  100.                 # Remove and print the portion of the line before the {
  101.                 s/^[^{]*{//;   # Remove upto and including the bracket
  102.                 $_s = $&;
  103.                 chop $_s;
  104.                 print $_s;   # Print everything except the bracket
  105.  
  106.                 if(m/}/)
  107.                 {
  108.                     s/^[^}]*}//;     # Chop off everything until the }
  109.                     $_expression = $&;  
  110.                     chop $_expression;
  111.                 }
  112.                 else
  113.                 {
  114.                     $_expression = $_; 
  115.                     chop $_expression; 
  116.                     $_ = "\n";
  117.                 }
  118.  
  119.                 # Process the expression
  120.                 #print eval($_definitions . $_expression);
  121.                 print eval($_expression);
  122.  
  123.  
  124.             }
  125.             print;   # Print the rest of the line
  126.         }
  127.  
  128.     }
  129.  
  130.  
  131.  
  132.